package com.xiaohong.search.feign;

import com.xiaohong.search.pojo.SkuInfo;
import entity.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

@FeignClient(name = "search-service")
@RequestMapping("/sku")
public interface SearchSkuFeign {

    /**
     * 数据导入
     */
    @GetMapping("/import")
    Result importData(HttpServletRequest httpServletRequest);

    /**
     * 删除所引
     * @return
     * @throws IOException
     */
    @DeleteMapping("/index/delete")
    Result deleteIndex();

    /**
     * 判断索引是否存在
     * @return
     * @throws IOException
     */
    @GetMapping("/index/exists")
    Result isIndexExists();

    /**
     * 添加文档
     * @param skuInfo
     * @return
     * @throws IOException
     */
    @PostMapping("/document/add")
    Result addOneDocument(@RequestBody SkuInfo skuInfo);

    /**
     * 获取文档
     * @param id
     * @return
     * @throws IOException
     */
    @GetMapping("/document/get/{id}")
    Result getDocument(@PathVariable(value = "id") String id);

    /**
     * 删除文档
     * @param id
     * @return
     * @throws IOException
     */
    @DeleteMapping("/document/delete/{id}")
    Result deleteDocument(@PathVariable(value = "id") String id);

    /**
     * 更新文档
     * @param skuInfo
     * @return
     */
    @PutMapping("/document/update")
    Result updateDocument(@RequestBody SkuInfo skuInfo);

    /**
     * 搜索
     * @param searchMap
     * @return
     */
    @GetMapping("/search")
    Map search(@RequestParam(required = false) Map<String,String> searchMap);

}
